<!DOCTYPE html>
<!--[if IE 9]>         <html class="no-js lt-ie10" lang="en"> <![endif]-->
<!--[if gt IE 9]><!-->
<html class="no-js" lang="cn">
	<!--<![endif]-->

	<head>
		<meta charset="utf-8">

		<title>新建问卷——问卷调查系统</title>

		<meta name="description" content="AppUI is a Web App Bootstrap Admin Template created by pixelcave and published on Themeforest">
		<meta name="author" content="pixelcave">
		<meta name="robots" content="noindex, nofollow">

		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<!-- Icons -->
		<!-- The following icons can be replaced with your own, they are used by desktop and mobile browsers -->
		<link rel="shortcut icon" href="img/favicon.png">
		<link rel="apple-touch-icon" href="img/icon57.png" sizes="57x57">
		<link rel="apple-touch-icon" href="img/icon72.png" sizes="72x72">
		<link rel="apple-touch-icon" href="img/icon76.png" sizes="76x76">
		<link rel="apple-touch-icon" href="img/icon114.png" sizes="114x114">
		<link rel="apple-touch-icon" href="img/icon120.png" sizes="120x120">
		<link rel="apple-touch-icon" href="img/icon144.png" sizes="144x144">
		<link rel="apple-touch-icon" href="img/icon152.png" sizes="152x152">
		<link rel="apple-touch-icon" href="img/icon180.png" sizes="180x180">
		<!-- END Icons -->

		<!-- Stylesheets -->
		<!-- Bootstrap is included in its original form, unaltered -->
		<link rel="stylesheet" href="css/bootstrap.min.css">

		<!-- Related styles of various icon packs and plugins -->
		<link rel="stylesheet" href="css/plugins.css">
		<link rel="stylesheet" href="css/page.css" />
		<!-- The main stylesheet of this template. All Bootstrap overwrites are defined in here -->
		<link rel="stylesheet" href="css/main.css">
		<link href="css/laypage.css" />
		<!-- Include a specific file here from css/themes/ folder to alter the default theme of the template -->

		<!-- The themes stylesheet of this template (for using specific theme color in individual elements - must included last) -->
		<link rel="stylesheet" href="css/themes/amethyst.css">
		<link rel="stylesheet" href="css/laypage.css">
		<!-- END Stylesheets -->

		<!-- Modernizr (browser feature detection library) -->
		<script src="js/vendor/modernizr-3.3.1.min.js"></script>
	</head>

	<body>
		<!-- Page Wrapper -->
		<!-- In the PHP version you can set the following options from inc/config file -->
		<!--
            Available classes:

            'page-loading'      enables page preloader
        -->
		<div id="page-wrapper" class="page-loading">
			<!-- Preloader -->
			<!-- Preloader functionality (initialized in js/app.js) - pageLoading() -->
			<!-- Used only if page preloader enabled from inc/config (PHP version) or the class 'page-loading' is added in #page-wrapper element (HTML version) -->
			<div class="preloader">
				<div class="inner">
					<!-- Animation spinner for all modern browsers -->
					<div class="preloader-spinner themed-background hidden-lt-ie10"></div>

					<!-- Text for IE9 -->
					<h3 class="text-primary visible-lt-ie10"><strong>Loading..</strong></h3>
				</div>
			</div>
			<!-- END Preloader -->

			<!-- Page Container -->
			<!-- In the PHP version you can set the following options from inc/config file -->
			<!--
                Available #page-container classes:

                'sidebar-light'                                 for a light main sidebar (You can add it along with any other class)

                'sidebar-visible-lg-mini'                       main sidebar condensed - Mini Navigation (> 991px)
                'sidebar-visible-lg-full'                       main sidebar full - Full Navigation (> 991px)

                'sidebar-alt-visible-lg'                        alternative sidebar visible by default (> 991px) (You can add it along with any other class)

                'header-fixed-top'                              has to be added only if the class 'navbar-fixed-top' was added on header.navbar
                'header-fixed-bottom'                           has to be added only if the class 'navbar-fixed-bottom' was added on header.navbar

                'fixed-width'                                   for a fixed width layout (can only be used with a static header/main sidebar layout)

                'enable-cookies'                                enables cookies for remembering active color theme when changed from the sidebar links (You can add it along with any other class)
            -->
			<div id="page-container" class="header-fixed-top">

				<!-- Main Container -->
				<div id="main-container">
					<!-- Header -->
					<!-- In the PHP version you can set the following options from inc/config file -->
					<!--
                        Available header.navbar classes:

                        'navbar-default'            for the default light header
                        'navbar-inverse'            for an alternative dark header

                        'navbar-fixed-top'          for a top fixed header (fixed main sidebar with scroll will be auto initialized, functionality can be found in js/app.js - handleSidebar())
                            'header-fixed-top'      has to be added on #page-container only if the class 'navbar-fixed-top' was added

                        'navbar-fixed-bottom'       for a bottom fixed header (fixed main sidebar with scroll will be auto initialized, functionality can be found in js/app.js - handleSidebar()))
                            'header-fixed-bottom'   has to be added on #page-container only if the class 'navbar-fixed-bottom' was added
                    -->
					<header class="navbar navbar-inverse navbar-fixed-top">
						<!-- Left Header Navigation -->
						<ul class="nav navbar-nav-custom">
							<!-- Header Link -->
							<li class="hidden-xs animation-fadeInQuick">
								<a href="questionnaire.html"><big> <strong>问道</strong></big></a>
							</li>
							<!-- END Header Link -->
						</ul>
						<!-- END Left Header Navigation -->

						<!-- Right Header Navigation -->
						<ul class="nav navbar-nav-custom pull-right">
							<!-- User Dropdown -->
							<li class="dropdown">
								<span> </span>
								<a onclick="logout()" class="dropdown-toggle" data-toggle="dropdown">
									注销
								</a>
							</li>
								<!-- END User Dropdown -->
						</ul>
						<!-- END Right Header Navigation -->
					</header>
					<!-- END Header -->

					<!-- Page content -->
					<div id="page-content">
						<!-- Blank Header -->
						<div class="content-header">
							<div class="row">
								<div class="col-sm-6">
									<div class="header-section">
										<h1 style="display: inline;">新建调查</h1>
										<h5 style="display: inline;">-基本信息设置</h5>
									</div>
								</div>
							</div>
						</div>
						<!-- END Blank Header -->

						<div class="row">
							<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
								<!-- Get Started Block -->
								<div class="block full">
									<!-- Get Started Title -->
									<!--action="page_forms_validation.html" method="post"-->
									<form id="form-validation" class="form-horizontal form-bordered">
										<div class="form-group">
											<label class="col-md-3 control-label" for="val-surveytype">调查类型<span class="text-danger">*</span></label>
											<div class="col-md-6">
												<select id="val-surveytype" name="val-surveytype" class="form-control">
													 
													<option value="true">实名</option>
													 
													<option value="false" class="hidden">匿名</option>
												</select>
											</div>
										</div>
										<div class="form-group" id="survey-dpt-outer">
											<label class="col-md-3 control-label" for="val-surveydepartment">调查部门<span class="text-danger">*</span></label>
											<div class="col-md-6">
												<select id="val-surveydepartment" name="val-surveydepartment" class="form-control">
													<option value="学生处">学生处</option>
													<option value="规划处">规划处</option>
												</select>
											</div>
										</div>
										<div class="form-group">
											<label class="col-md-3 control-label" id='surveytitle' for="val-surveyname">调查名称<span class="text-danger">*</span></label>
											<div class="col-md-6">
												<input type="text" id="val-surveyname" name="val-surveyname" class="form-control">
												<div id="string" style="color: red;margin-top: 2%;margin-left: 1%;display: block;" class="str hidden">
												
											</div>
											</div>
										</div>
						
										<div class="form-group">
											<label class="col-md-3 control-label" for="val-surveybinding">绑定问卷<span class="text-danger">*</span></label>
											<div class="col-md-6">
												<select id="val-surveybinding" name="val-surveybinding" class="form-control">
													<option>当前问卷列表为空</option>
												</select>
											</div>
										</div>
										<div class="form-group">
											<label class="col-md-3 control-label" for="example-daterange1">调查周期<span class="text-danger">*</span></label>
											<div class="col-md-6">
												<div class="input-group input-daterange" data-date-format="yyyy-mm-dd">
													<input type="text" id="example-daterange1" name="example-daterange1" class="form-control " placeholder="起始日期"  data-date-end-date = “0d”>
													<span class="input-group-addon">至</span>
													<input type="text" id="example-daterange2" name="example-daterange2" class="form-control" placeholder="终止日期" >
												</div>
												<div id="string1" style="color: red;margin-top: 2%;margin-left: 1%;" class="str1 hidden">
												
												</div>
											</div>
										</div>
										
										<div class="form-group form-actions" style="margin-top: 5%;">
											<div class="col-md-8 col-md-offset-3">
												<button class="btn btn-effect-ripple btn-primary" onclick="next()" id="btn-real" type="button">确定</button>
												 
												<button type="reset" class="btn btn-effect-ripple btn-danger">重置</button>
											</div>
										</div>
									</form>
									<!-- END Get Started Title -->
								</div>
								<!-- END Get Started Block -->
							</div>
						</div>
					</div>
					<!-- END Page Content -->
				</div>
				<!-- END Main Container -->
			</div>
			<!-- END Page Container -->
		</div>
		<!-- END Page Wrapper -->

		<!-- jQuery, Bootstrap, jQuery plugins and Custom JS code -->
		<script src="js/vendor/jquery-2.2.4.min.js"></script>
		<script src="js/vendor/bootstrap.min.js"></script>
		<script src="js/plugins.js"></script>
		<script src="js/app.js"></script>
		<script src="js/lay/modules/laypage.js"></script>
		<script src="js/layui.js"></script>
		<script src="js/layui.all.js"></script>
		<script type="text/javascript">
			//url
			var ip ,
				getUrl = '/list';
			var id = '';

			$(function() {
			 var configJson='js/confing.json'
			$.getJSON(configJson,function(data){
				ip=data.urlip;
				identi()
				getID();
				getAllDpt();
				getList();
			});
			});
			
			//判断是否登录
			function identi()
			{
				$.ajax({
     				type: "get",
   					url: ip+"/user/type",
  					data:{
  						
  					},
    				async: true,
    				dataType: "json",
     				xhrFields: {withCredentials: true},
    				crossDomain:true,
    				success: function(res) {
						if(res.code==0)
						{
							type=res.data;
							
						}
    				},
    				async:false
     			});
			}
			
			function getID() {
				url = location.search;
				if(url.indexOf("?") != -1) { //判断是否有参数
					var str = url.substr(1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
					strs = str.split("="); //用等号进行分隔 （因为知道只有一个参数 所以直接用等号进分隔 如果有多个参数 要用&号分隔 再用等号进行分隔）
					console.log(strs[1]); //直接弹出第一个参数 （如果有多个参数 还要进行循环的）
					id = strs[1];
				} else {
					id = '-1';
				}
			}

			function logout(){
				$.ajax({
					type:"get",
					url:ip+"/logout",
					data:{},
					async:true,
					dataType: "json",
					xhrFields: {withCredentials: true},
      				crossDomain:true,
      				success:function(res)
      				{
      					 if(!res.code){
      					 	window.location.href="login.html"
      					 }
      				}
				});	
			}
			var total;
			//获取下拉框数据
			function getList(pageconf) {
				if(!pageconf){
					pageconf={};
					pageconf.pageSize=6;
					pageconf.currentPage=1;
				}
				$.ajax({
					type: "get",
					url: ip + getUrl,
					data: {
						"page":pageconf.currentPage,
						"size":pageconf.pageSize
					},
					xhrFields: {withCredentials: true},
    				crossDomain:true,
					success: function(res) {
						console.log(res);
						//填充
						if(typeof res.data!="string"){
							total=res.data.total;
							getListall(total);
							//setSelect(res.data.datas);
							 
						}
					},
					async: true
				});
			}
			function getListall(total) {
				$.ajax({
					type: "get",
					url: ip + getUrl,
					data: {
						"page":1,
						"size":total
					},
					xhrFields: {withCredentials: true},
    				crossDomain:true,
					success: function(res) {
						console.log(res);
						//填充
						if(typeof res.data!="string"){
							setSelect(res.data.datas);
							 
						}
					},
					async: true
				});
			}
			
			

			function getAllDpt() {
				$.ajax({
					type: "get",
					url: ip + '/survey/sections',
					xhrFields: {withCredentials: true},
      				crossDomain:true,
					success: function(res) {
						console.log(res);
						//填充
						setSelect1(res.data);
					},
					async: true
				});
			}
			
			
		 
			
			var options = '';
			function setSelect(list) {
				console.log(list);
				 
					console.log("dssds")
				$.each(list, function(index, value) {
					console.log(value);
					options = options + '<option value="' + value.id + '">' + value.name + '</option>';
				});
				 
				$("#val-surveybinding").html(options);
				//如果是根据问卷新建调查
				if(id != -1) {
					$("#val-surveybinding").val(id);
					$("#val-surveybinding").attr("disabled", true);
				}
				

			}

			function setSelect1(list) {
				console.log(list);
				var options = '';
				$.each(list, function(index, value) {
					console.log(value);
					options = options + '<option value="' + value + '">' + value + '</option>';
				});
				$("#val-surveydepartment").html(options);

			}

			function next() {
				var submitUrl = '/survey/build';
				$(".str").addClass("hidden")
				$(".str1").addClass("hidden")
				//提交调查信息
				if(!$("#val-surveyname").val()||!$("#example-daterange1").val()||!$("#example-daterange2").val()){
					if(!$("#val-surveyname").val()){
						$("#string").html("*调查名称不能为空");
						$(".str").removeClass("hidden")
					}else{
						$(".str").addClass("hidden")
					}
					if(!$("#example-daterange1").val()||!$("#example-daterange2").val()){
						$("#string1").html("*调查周期不能为空");
						$(".str1").removeClass("hidden")
					}else{
						$(".str1").addClass("hidden")
					}
				}
				else{
				$.ajax({
					type: "post",
					url: ip + submitUrl,
					data: JSON.stringify({
						title: $("#val-surveyname").val(),
						privately: $("#val-surveytype").val(),
						questionsID: $("#val-surveybinding").val(),
						startTime: $("#example-daterange1").val(),
						endTime: $("#example-daterange2").val(),
						description: $("#val-surveydescription").val(),
						section: $("#val-surveydepartment").val()
						
					}),
					dataType: "json",
					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log("@@@@@@@@@@@22");
						//						alert(res);
						if(res.code == 0) {
							if(typeof res.data=="string"){
								$("#string").html("*"+res.data);
								$(".str").removeClass("hidden")
							}
							else{
								if($("#val-surveytype").val()=="true"){
									var url = 'surveyDetail.html?id=' + res.data.id ;
									location.href = url;
								}else{
									var url = 'surveyDetail_unreal.html?id=' + res.data.id ;
									location.href = url;
								}
							}
						}

						//						window.event.returnValue=false;
					},
					async: true
				});
				}
			}

			function checkDetail() {
				
				//window.location.href = "surveyDetail_unreal.html";
				//window.event.returnValue = false;
			}

			$("#val-surveytype").on('change', function() {
				//如果是实名
				if($(this).val() == 'true') {
					//判断"确定"按钮是否隐藏
					//如果没有隐藏
					//如果"下一步"按钮隐藏
					if($("#btn-real").hasClass("hidden")) {
						$("#btn-real").removeClass("hidden");
					}
					if($("#survey-dpt-outer").hasClass("hidden")) {
						$("#survey-dpt-outer").removeClass("hidden");
					}
				}
				//匿名
				else {
					if(!$("#btn-real").hasClass("hidden")) {
						$("#btn-real").remove("hidden");
					}
					if(!$("#survey-dpt-outer").hasClass("hidden")) {
						$("#survey-dpt-outer").addClass("hidden");
					}
				}
				console.log($("#val-surveytype option:checked").text());
				/*if($("#val-surveytype option:checked").text() == '实名(满意度调查)') {
					if($("#survey-dpt-outer").hasClass("hidden")) {
						$("#survey-dpt-outer").removeClass("hidden");
					}
				} else {
					if(!$("#survey-dpt-outer").hasClass("hidden")) {
						$("#survey-dpt-outer").addClass("hidden");
					}
				}*/
			});
			
		 
		</script>
	</body>

</html>